package ui;

// 爷爷
class GrandFather extends Object {
    private int data;
    protected int dataOfGrandFather;

    public GrandFather(int data) {
        dataOfGrandFather = data;
        System.out.println("GrandFather对象诞生了！");
    }

    public void setValue(int data) {
        this.dataOfGrandFather = data;
    }
}

class Father extends GrandFather {
    protected int dataOfFather;

    public void setValue(int data) {
        this.dataOfFather=data;
    }

    public Father(int data) {
        // 给GrandFather构造函数传参
        super(data);
        this.dataOfFather = data;
        super.dataOfGrandFather = data; //this.dataOfGrandFather = data;
        this.setValue(data); // this.只能调用子类型自己定义的函数版本
        super.setValue(data); // super.能调用父类型声明函数版本
        System.out.println("Father对象诞生了！");
    }
}

class Son extends Father {
    public Son(int data) {
        // 给Father构造函数传参
        super(data);

        System.out.println("Son对象诞生了！");
    }
}


public class Test {
    public static void main(String[] args) {
        Son son1 = new Son(12);
        Son son2 = new Son(13);
        System.out.println(son1.dataOfGrandFather);
        System.out.println(son1.dataOfFather);
        boolean isEquare = son1.equals(son2);

        // 调用的是Father声明的版本，因为GrandFather声明的版本被Father的同名版本隐藏掉了！
        son1.setValue(14);
    }
}
